import socket

def main():
    host = 'www.baidu.com'
    port = 80

    data = b'GET / HTTP/1.1\r\n' + \
           f'Host: {host}\r\n'.encode() + \
           b'Accept-Encoding: identity\r\n' + \
           b'User-Agent: test\r\n' + \
           b'Connection: close\r\n' + \
           b'\r\n'
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    with s:
        s.settimeout(5)
        s.connect((host, port))
        s.send(data)
        ar = b''
        while True:
            r = s.recv(16)
            if len(r) < 1:
                break
            ar += r
        print(ar.decode())

if __name__=='__main__':
    main()